The HTML Production for Java class library is an open source
class library that encapsulates the gory details of creating HTML
for use in JSP and Servlets. Access to the project is provided courtesy of
Source Forge.
HTML Production for Java allows developers to create complicated HTML
structures by combining relatively simple objects together. For example,
most sites have a consistent look for all of the input forms for the site.
Rather than typing lots of HTML in the Servlets or JSPs, the developer should
be able to use our HTML production library to encapsulate
the presentation logic for the input forms. In the following example, the UI developer
describes a form in terms of defined fields and then asks a Form object to generate the
HTML for the form.
The client code would look like:
FormDescription form_description = new FormDescription("data", "Data", "Please enter some data. ");
InputGroupDescription personal_group =
new InputGroupDescription("Personal Information", "Please enter your personal information");
personal_group.addInputDescription(FieldDescription.FIRST_NAME);
personal_group.addInputDescription(FieldDescription.MIDDLE_INITIAL);
personal_group.addInputDescription(FieldDescription.LAST_NAME);
personal_group.addInputDescription(SelectionDescription.GENDER);
personal_group.addInputDescription(FieldDescription.AGE);
personal_group.addInputDescription(SelectionDescription.SALARY_RANGE);
personal_group.addInputDescription(SelectionDescription.TECHNICAL_EXPERTISE);
form_description.addGroup(personal_group);
Form form = new Form("/silly/formValidationServlet", form_description, current_values);
form.addButton("submit", "Submit");
Page page = new Page("Test Form", "./Default.css");
page.addToBody(form);
page.buildContent(buffer);
This allows the form to be constructed very easily and very naturally,
without any knowledge of HTML.
Developers can use a similar approach to develop their own reusable HTML producers for page
layouts, fancy navigation bars, etc. These producers can be used
from both Servlets or JSPs.
While this project will provide some high level structures, it is mostly
focused on providing solid building blocks that YOU can use to build
interesting project level components as described above. For example,
it encapsulates the complexity of the table tag inside of a Table class that
allows you to add any HTML producer to specific spots in the table:
Table layout = new Table();
layout.setWidth(700);
Link link = new Link("./about.html");
link.add(new Text(Style.LINK, "About us");
Image spot = new Image("/images/spot.jpeg");
layout.setProducerAt(0,0, link);
layout.setProducerAt(1,1, spot);
Enjoy!